<template>
	<view class="container wallet">
		<view class="wallet_total uni-radius">
			<view class="total_top">
				<view class="tl" >
					<view class="txt">{{tabList[type]['name']}}</view>
					<view class="num">
						<text v-show="type==0">{{usermoney.yk_static || 0.00}}</text>
						<text v-show="type==1">{{usermoney.money || 0.00}}</text>
						<text v-show="type==2">{{usermoney.sc_money || 0}}</text>
					</view>
				</view>
				<view class="tr">
					<!-- <button class="rbtn" >充值</button> -->
					<button v-show="type==0" class="rbtn" @click="$u.route('/pages/user/deposit/deposit')">充值</button>
					<button v-show="type==1" class="rbtn1" @click="$u.route('/pages/pay/withdrawal/withdrawal')">提现</button>
					<!-- <button class="rbtn1" @click="$api.msg('开发中')">提现</button> -->
				</view>
			</view>
		<!-- 	<view class="total_bt">
				<view class="item">
					<view class="num">2000</view>
					<view class="txt">金币</view>
				</view>
				<view class="item">
					<view class="num">2000</view>
					<view class="txt">购物券</view>
				</view>
				<view class="item">
					<view class="num">2000</view>
					<view class="txt">广告积分</view>
				</view>
				<view class="item">
					<view class="num">2000</view>
					<view class="txt">拼团积分</view>
				</view>
			</view> -->
		</view>
		<!-- <view class="wallet_btn">
			<button class="wbtn" @click="goRecharge">充值</button>
			<button class="wbtn1" @click="goWithdrawal">提现</button>
		</view> -->
		
		<view class="wallet_tit">资金明细</view>
		<!-- <view class="wallet_tabs">
			<u-tabs name="type" lineColor="#f06c7a" font-size="28" :list="tabList" :is-scroll="false" :current="tabCurrent" @change="tabChange"></u-tabs>
		</view> -->
		
		<view class="fund_list">
			<view class="item bg uni-radius" v-for="item in records">
				<view class="item_left">
					<view class="tit" style="color: red;" v-if="item.money<0 || item.type == -1">{{item.money}}</view>
					<view class="num1" v-else >{{item.money}}</view>
					<text class="time">{{formatData(item.createdate)}}</text>
				</view>
				
				<view class="item_right">
					
					<view class="num1" v-show="type==1">
						<text>{{item.type}}</text>
					</view>
					<text>{{item.content}}</text>
				</view>
			</view>
			
		</view>
		<u-empty v-show="records.length==0" iconSize="300" textSize="40" mode="list">
		</u-empty>
		<u-loadmore v-show="records.length>0" class="uni-pt-6 uni-pb-6" fontSize="28" :status="loadingType"  color="#a0a2b4" lineColor="#a0a2b4"  :dashed="true"/>
		<!-- 登录弹窗 -->
		<!-- <my-login :loginshow="!islogin" :req="true"></my-login> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadingType: 'more',
				userInfo : {},
				ewm: "",
				barStyle:{
					background:'#fa436a'
				},
				tabList: [{
					name: '金豆'
				}, {
					name: '余额'
				}, {
					name: '抵扣券',
				}
				],
				tabCurrent: 0,
				dataList: "",
				records:[],
				page:1,
				usermoney:{},
				type:0,
				apiurl:[
					'pay/getYkLog.html?page=',
					'pay/getMoneyLog.html?page=',
					'pay/getScLog.html?page='
				]
			}
		},
		async onLoad(e) {
			if(e.type)this.type = e.type;
			
			this.load();
		},
		async onShow(){
			//var result = (await this.$ajax.get('users/shareQRcode.html'));
			// var result = (await this.$ajax.get('users/getBasicUserInfo.html'))
			
			// //console.log(result.data.data);
			
			// this.ewm = this.apiurl + "users/shareQRcode.html?userid=" + result.data.data.id
			
			//
			// var result = (await this.$ajax.get('money/getMoneyLog.html'))
			// this.dataList = result.data.data
			
			// var result = (await this.$ajax.get('users/getUserMoney.html'));
			// this.money = result.data.data.money;
			
			// console.log(this.money)
			
			this.getRecords();
		},
		async onReachBottom() {
			this.getRecords();
		},
		methods: {
			async load(e){
				
				this.islogin = uni.getStorageSync('USERS_KEY')?true : false;
				console.log('islogin:'+this.islogin);
				if(this.islogin){
					// var result = await this.$ajax.get('users/getUserInfo.html');
					// console.log(result1);
					// uni.setStorageSync('USERS_KEY',result.data.data);
					// this.userinfo = result.data.data;
					// console.log(this.userinfo);
					var result = await this.$ajax.get('users/getusermoney.html');//获取余额
					this.usermoney = result.data.data;
					uni.setStorageSync('usermoney',result.data.data);
				}
			},
			tabChange(index) {
				console.log(index.index);
				this.tabCurrent = index.index;
			},
			async getRecords(){
				this.loadingType = 'loding';
				var result = (await this.$ajax.get(this.apiurl[this.type]+this.page));
				this.page++;
				console.log(result);
				if(result.data.data.length>0){
					for (let i=0;i<result.data.data.length;i++) {
						this.records.push(result.data.data[i]);
					};
				}else{
					this.$api.msg('没有更多了');
					this.loadingType = 'nomore';
				}
				this.loadingType = 'more';
				// console.log(result.data.data);
			},
			showEWM(){
				uni.navigateTo({
					url: `/pages/wallet/mycode`
				})
			},
			showSKM(){
				uni.navigateTo({
				 	url: `/pages/wallet/shopcode`
				})
			},
			async goRecharge(){
				// this.$api.msg("正在开发");
				// return;
				var result = (await this.$ajax.get('users/getUserInfo.html'));
				this.userInfo = result.data.data;
				
				console.log(this.userInfo);
				
				uni.navigateTo({
					url: `/pages/wallet/recharge`
				})
				
				return;
				
				if(this.userInfo.id == 6500 || this.userInfo.id == 13229 || this.userInfo.id == 5171) {
					uni.navigateTo({
						url: `/pages/wallet/recharge`
					})
				} else {
					this.$api.msg("正在开发");
					return;
				}
			},
			
			goWithdrawal(){
				uni.navigateTo({
					url: `/pages/wallet/withdrawal`
				})
			},
			formatData(date){			
				//时间戳转换方法    date:时间戳数字
				var date = new Date(date*1000);
				var YY = date.getFullYear() + '-';
				var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
				var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
				var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
				var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
				return YY + MM + DD +" "+hh + mm + ss;
			}
			
		},
		
		// onBackPress(e){
		// 	console.log("监听返回按钮事件",e);
		// 	uni.navigateTo({
		// 		url:"/pages/user/user"
		// 	})
		// 	// 此处一定姚要return为true，否则页面不会返回到指定路径
		// 	return true;
		// }
	}
</script>

<style lang='scss'>
	page{
	}
	.wallet{
		
	}
	.wallet_total{
		/* margin:0rpx 30rpx 20rpx 30rpx; */
		
		height:auto;
		overflow:hidden;
		/* background:$base-color; */
		/* box-shadow:0 10rpx 20rpx rgba($color: #000000, $alpha:0.2); */
		/* border-radius:20rpx; */
		text-align: center;
		position:relative;
		background: $uni-bg-color-main;
		.total_top{
			width:100%;
			box-sizing: border-box;
			height:auto;
			overflow:hidden;
			padding:50rpx 40rpx 50rpx 40rpx;
			display:flex;
			justify-content:space-between;
			align-items:flex-start;
			position: relative;
			z-index: 1;
			.tl{
				flex:1;
				text-align:left;
			}
			.tr{}
			button{
				height:60rpx;
				line-height:60rpx;
				color:#fff;
				margin:0;
				font-size:28rpx;
				font-size:28rpx;
				border-radius:100rpx;
			}
			button:after{
				display: none;
			}
			.rbtn{
				width:160rpx;
				background:#fff;
				color:#333;
				padding:0 40rpx;
				margin-bottom:30rpx;
			}
			.rbtn1{
				width:160rpx;
				color: $uni-text-color;
				background:$uni-bg-color;
				margin:30rpx 30rpx 0 0;
			}
		}
		.txt{
			font-size:26rpx;
			color:#fff;
			margin:0 0 15rpx 0;
		}
		.num{
			font-size:30rpx;
			color:#fff;
			text{
				font-size:70rpx;
				/* font-weight:bold; */
			}
		}
		.total_bt{
			height:auto;
			overflow:hidden;
			padding:20rpx 20rpx 50rpx 0;
			display:flex;
			justify-content:space-between;
			align-items:flex-start;
			position: relative;
			z-index:1;
			.item{
				width:25%;
			}
			.txt{
				font-size:26rpx;
				color:#fff;
				margin:10rpx 0 0rpx 0;
			}
			.num{
				/* font-size:30rpx; */
			}
		}
	}
	.wallet_btn{
		display: flex;
		justify-content:space-around;
		align-items: center;
		margin:40rpx 40rpx;
		button{
			width:40%;
			height:70rpx;
			line-height:70rpx;
			font-size:30rpx;
			color:#fff;
			margin:0;
			border-radius:100rpx;
		}
		button:after{
			display: none;
		}
		.wbtn{
			background:#333;
		}
		.wbtn1{
			background:#999;
		}
	}
	.wallet_tit{
		font-size:30rpx;
		color:$uni-text-color;
		font-weight:bold;
		margin:30rpx 0 0 20rpx;
	}
	.fund_list{
		margin:10rpx;
		height:auto;
		overflow:hidden;
		.item{
			display: flex;
			justify-content: space-between;
			align-items:flex-start;
			/* height:auto;
			overflow:hidden;
			
			
			margin:0rpx 0 20rpx 0;
			padding:20rpx;
			margin-top: 20rpx;
			background-color: #2f3043; */
			/* border-top:1rpx #eee solid; */
			.item_left{
				text-align: left;
				.tit{
					font-size:28rpx;
					margin-bottom:10rpx;
				}
				.time{
					font-size:24rpx;
					color:#999;
				}
				.num1{
					font-size:30rpx;
					color:#093;
					margin-bottom:13rpx;
				}
			}
			.item_right{
				text-align: right;
				.num{
					font-size:30rpx;
					color:#fa436a;
					margin-bottom:13rpx;
				}
				.code{
					font-size: 24rpx;
					color:#999;
				}
				
				.num1{
					font-size:30rpx;
					color:#093;
					margin-bottom:13rpx;
				}
				.rz{
					font-size: 24rpx;
					color:#999;
				}
			}
		}
		
	}
	.code1{
		color: #093;
	}
	.code2{
		color: crimson;
	}
</style>
